package com.sinitek.sirm.elfinder.support.spring.converter;

import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;

import java.util.HashSet;
import java.util.Set;

/**
 * 定制的ConversionService，用于注入定制的类型转换器
 * @author yg.huang
 * @version v1.0
 *          DATE  2017/5/10
 */
public class CustomFormattingConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {
    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();
        /*
          删除默认的String 转Number的转换器
         */
        this.getObject().removeConvertible(String.class,Number.class);
        Set<CustomNumberConverter> converters=new HashSet<CustomNumberConverter>();
        /*
           加入定制的String 转Number的转换器
         */
        converters.add(new CustomNumberConverter(this.getObject()));
        ConversionServiceFactory.registerConverters(converters, this.getObject());
    }
}
